﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Experimental.Rendering.RenderGraphModule;
using UnityEngine.Rendering;

namespace BPipeline.Runtime.RenderPass
{
    public class PresentPass
    {
        static ShaderTagId pass = new ShaderTagId(nameof(PresentPass));
        public class PresentPassData
        {
            public TextureHandle src;

            public TextureHandle bgColor;
        }
        static public PresentPassData Excute(RenderGraph renderGraph, Camera camera,TextureHandle src)
        {
            using (var builder = renderGraph.AddRenderPass<PresentPassData>(nameof(PresentPass), out var presentData))
            {
                presentData.src = builder.ReadTexture(src);
                presentData.bgColor = renderGraph.ImportBackbuffer(camera.targetTexture);
                builder.UseColorBuffer(presentData.bgColor, 0);

                builder.SetRenderFunc(
                    (PresentPassData PresentPassData, RenderGraphContext ctx) =>
                    {
                        //ctx.cmd.Blit(PresentPassData.src, presentData.bgColor, new Vector2(1, -1), new Vector2(0, 1));
                        ctx.cmd.Blit(PresentPassData.src, presentData.bgColor);
                    });

                return presentData;
            }

        }
    }
}
